From: NTFL15A@prodigy.com (Lynn Boyett) Newsgroups: comp.graphics.algorithms Subject: Re: Sine (or Cosine) Algo. needed Date: 28 Dec 1996 06:08:07 GMT Organization: Prodigy Services Company 1-800-PRODIGY Lines: 102 Distribution: world Message-ID: <5a2dg7$1s1e@usenetw1.news.prodigy.com> References: <32c15a48.41d8@popalex1.linknet.net> <32c3e80c.6716@nstl.com> <32c4daba.4406@sn.no> NNTP-Posting-Host: innugap4-int.news.prodigy.com X-Newsreader: Version 1.2 Francois wrote about formula for sine and cosine functions. The formula used are from the Taylor series for sine and cosine functions. oo 3 5 7 __ (2*n-1) n+1 x x x sin(x) = \ x * (-1) = x - -- + -- - -- + ... /__ ------------------ 3! 5! 7! n = 1 (2*n-1) ! oo 2 4 6 __ (2*n+1) n x x x cos(x) = \ x * (-1) = 1 - -- + -- - -- + ... /__ ------------------ 2! 4! 6! n = 0 (2*n+1) ! This is true for all x such that (-oo < x < +oo). This is radian measure. With an increase in speed of 10% to 35% (as he reported), it would be an advantage over the library calculations. Speed could be increased by not duplicating calculations, such as the following: 2 let u := x , then the expanded equations become: 2 3 u u u 2 sin(x) = x*(1 - -- + -- - -- + ... where u = x 3! 5! 7! 2 3 u u u 2 cos(x) = 1 - -- + -- - -- + ... where u = x 2! 4! 6! Calculate 'u' once and reuse it in the rest of the equations instead of calculating 'x*x' each time. By using a table for the reciprical of factorials and with the calculation of x*x the process would be faster. In Assembly, the coefficent values could be in two tables with the references to them being the only difference. Then there would be an 'overlap' in that 2 3 u u u (- -- + -- - -- + ... 2! 4! 6! 3! 5! 7! is the same in both equations. Remember that the routine would call (relative, etc) either 2!,4!,6! or 3!,5!,7!. Actually, you would call the recipricals. You would then add one to the answer. This is Cosine. With 'even' factorials. And for Sine you would need a little more work. Multiple by the original value 'x'. With the 'odd' factorials. This overlap would also reduce the space required. Also, knowing the cooefficients can allow any programmer the precision that they want - like 6 decimal places or 16 places (if their computer can handle it) or even more. **************************************************************** A very elementary routine would be sine: save the original value in a holding place reference the recipricals of factorials by relative, etc. goto around cosine: save a one in a holding place reference the recipricals of factorials by relative, etc. around: calculate the square of the original value compute the main equation(s) add one multiply by the value in the holding place from above (either one or the original value) This could be cleaned up a lot.